package com.pyue.eam.job;

import com.pyue.eam.job.service.RegiCompanyImpl;
import com.pyue.eam.admin.utils.TenantHandleUtil;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

@Component
@Slf4j
@AllArgsConstructor
public class CommonJobs extends BaseJobUtil {
    private final TenantHandleUtil tenantHandleUtil;
    private final RegiCompanyImpl regiCompanyImpl;

    /**
     * 月绩效指标
     */
    @XxlJob("performanceMonth")
    @Transactional(rollbackFor = Exception.class)
    public void sysMonthBeforeJob() {
        // 月初执行昨天的月绩效指标
        LocalDate finalDate = getDateIfPresentYesterday();
        tenantHandleUtil.multiTenantJobHandle((tenantId) -> {
            // todo bizCode
            System.out.println(finalDate);
        });
        XxlJobHelper.handleSuccess();
    }


    /**
     * 公司和团长的头像为空问题
     */
    @XxlJob("companyAndRegiHeadJob")
    @Transactional(rollbackFor = Exception.class)
    public void companyAndRegiHeadJob() {
        tenantHandleUtil.multiTenantJobHandle((tenantId) -> {
            // todo bizCode
            regiCompanyImpl.companyAndRegiHeadJob();
        });
        XxlJobHelper.handleSuccess();
    }

}
